<?php

class Navigation_Form_Menuitem extends Zend_Form {

	public function init() {
		$this->setMethod('post');
		
		$locales = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getOption('locales');
		$defaultLang = key($locales);
		
		$subFormLabel = new Zend_Form_SubForm();
        $subFormLabel->removeDecorator('Fieldset');
        $subFormTitle = new Zend_Form_SubForm();
        $subFormTitle->removeDecorator('Fieldset');
		
        foreach($locales as $lang=>$value) {
        	$name = $this->createElement('text', $lang);
			$name->setLabel(strtoupper($lang) . ' ' . _('Label:'));
			$name->addFilters(array('StringTrim','StripTags'));
			$name->setAttrib('size', '32');
			$name->setAttrib('maxlength', '255');
			
			
			$title = $this->createElement('text', $lang);
			$title->setLabel(strtoupper($lang) . ' ' . _('Descriptive text:'));
			$title->addFilters(array('StringTrim','StripTags'));
			$title->setAttrib('size', '32');
			$title->setAttrib('maxlength', '255');
			
			
			if($defaultLang == $lang) {
				$name->setRequired(true);
				$title->setRequired(true);
			}
			
			$subFormLabel->addElement($name);
			$subFormTitle->addElement($title);
        }
		
		$this->addSubForm($subFormLabel, 'name');
		$this->addSubForm($subFormTitle, 'title');
		
		
		$target = $this->createElement('radio', 'target');
		$target->setLabel(_('Target:'));
		$target->setSeparator('<br />');
		$target->addMultiOptions(array(
			'1' => _('Loads the page in the current window.'),
			'0' => _('Loads the page in a new browser window.')
		));
		$target->setRequired(true);
		$target->setValue('1');
		
		$menu_id = $this->createElement('select', 'menu_id');
		$menu_id->setLabel(_('Menu:'));
		$menu_id->setRequired(true);
		
		$parent = $this->createElement('select', 'parent');
		$parent->setLabel(_('Parent link:'));
		$parent->setRequired(true);
		
		$published = $this->createElement('radio', 'published');
		$published->setLabel(_('Published:'));
		$published->setRequired(true);
		$published->addMultiOptions(array(1 => _('Yes'), 0 => _('No')));
		$published->setSeparator(' ');
		$published->setValue(1);
		
		$reference = $this->createElement('select', 'ref');
		$reference->setLabel(_('Reference guide:'));
		$reference->addMultiOptions(array('sitemap' => _('Select from sitemap'), 'uri' => _('URI')));
		$reference->setValue('uri');
		
		$sitemap = $this->createElement('select', 'sitemap');
		$sitemap->setAttrib('disabled', 'disabled');
		
		$uri = $this->createElement('text', 'uri');
		$uri->setAttrib('size', '32');
		$uri->setValue('http://');
		
		$submit = $this->createElement('submit', 'submit');
		$submit->setLabel(_('Save'));
		
		$this->addElements(array($target, $parent, $menu_id, $published, $reference, $sitemap, $uri, $submit));
		
	}
}